<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<?php


include_once 'conn.php';
if(isset($_POST['submit']))
{
$sql="insert into message (id,user,title,content,lastdate)" .
"values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";

mysql_query($sql);
echo "<script>alert('提交成功！返回首页。');location.href='add.php';</script>";
}
?>

<script language="javascript">
function checkpost()
{
if (myform.user.value=="")
    {
     alert("请输入用户名");
myform.user.focus();
return false;
    }
if (myform.title.value.length<5)
    {
     alert("标题不能小于5个字符");
myform.title.focus();
return false;
    }
     if (myform.content.value.length<5)
    {
     alert("留言内容不能小于10个字符");
myform.content.focus();
return false;
     }

}
</script>
<style type="text/css">
<!--
body,td,th {
	font-size: 12px;
	background-color: #9CC;
}
-->
</style>
<link href="CSS.css" rel="stylesheet" type="text/css" />
<body>
<form name="myform" action="add.php" method="post" onSubmit="return checkpost();">
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
      <td height="26" colspan="2" align="center" bgcolor="#F9F9F9"><a href="add.php">添加留言</a> <a href="show.php">查看留言</a> <a href="login.php">登陆</a></td>
    </tr>
    <tr>
      <td width="79" height="34" align="center" bgcolor="#FFFFFF">用户:</td>
      <td width="518" bgcolor="#FFFFFF"><label>
        <input name="user" type="text" id="username" size="40">
      </label></td>
    </tr>
    <tr>
      <td height="43" align="center" bgcolor="#FFFFFF">标题:</td>
      <td height="43" bgcolor="#FFFFFF"><input name="title" type="text" id="title" size="40" /></td>
    </tr>
    <tr>
      <td height="100" align="center" bgcolor="#FFFFFF">留言:</td>
      <td height="100" bgcolor="#FFFFFF"><textarea name="content" cols="50" rows="5" id="content"></textarea></td>
    </tr>
    <tr>
      <td height="55" colspan="2" align="center" bgcolor="#FFFFFF"><label>
        <input type="submit" name="submit" id="button" value="提交">
      </label></td>
    </tr>
</table>
</form>
</body>
